home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / nodelist.c < prev    next >
C/C++ Source or Header  |  1996-10-13  |  8KB  |  295 lines

  1. /*
  2.  *                              nodelist.c
  3.  *
  4.  * Generates list of rooms shared with each node.
  5.  */
  6.  
  7. /*
  8.  *                              history
  9.  *
  10.  * 89Aug14 HAW  Handle virtual rooms as well.
  11.  * 87Dec06 HAW  Created.
  12.  */
  13.  
  14. #include "ctdl.h"    /* header file  */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <math.h>
  19. #include <ctype.h>
  20. #include <time.h>
  21. #include <proto/exec.h>
  22. #include <dos/dos.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include "exec/memory.h"
  25. #include "exec/ports.h"
  26. #include "exec/exec.h"
  27.  
  28. /*
  29.  *                              contents
  30.  *
  31.  *      crashout()              irrecoverable error
  32.  *      main()                  Main controller for this program
  33.  *      openFile()              opens a .sys file
  34.  */
  35.  
  36. extern rTable *roomTab;         /* RAM index of rooms           */
  37. extern CONFIG cfg;              /* A buncha variables           */
  38. extern FILE     *netfl;
  39. extern NetBuffer netBuf;
  40. extern NetTable *netTab;
  41. extern VirtualRoom *VRoomTab;
  42. extern char VirtualInUse;
  43. extern VirtNet  *VirtNetList;
  44. extern int  thisNet, VirtSize, VNetSize;
  45. FILE *netLog;
  46.  
  47. int ListNodes(int alive);
  48. int ListByNodes(void);
  49. void CheckNet(int i, int roomSlot);
  50. void CheckVirt(int TheVirt, int NetRover);
  51. void PrintNetRooms(void);
  52. void PrintVirtuals(void);
  53.  
  54. /*
  55.  * crashout()
  56.  *
  57.  * This function handles an irrecoverable error.
  58.  */
  59. void crashout(str)
  60. char *str;
  61. {
  62.     exit(printf(str));
  63. }
  64.  
  65. /*
  66.  * main()
  67.  *
  68.  * This is the main controller.
  69.  */
  70. int main(int, char **);
  71. int main(argc, argv)
  72. int argc;
  73. char **argv;
  74. {
  75.     SYS_FILE netFile;
  76.     int Index, NetRover;
  77.  
  78.     cfg.weAre = UTILITY;
  79.     fprintf(stderr, "Citadel Node versus Room Cross Reference list %s\n%s\n"
  80.     , VERSION_NAME, COPYRIGHT);
  81.     if (readSysTab(FALSE, TRUE)) {
  82.         mvToHomeDisk(&cfg.homeArea);
  83.         makeSysName(netFile, "ctdlnet.sys", &cfg.netArea);
  84.         openFile(netFile, &netfl);
  85.         initNetBuf(&netBuf);
  86.  
  87.         if (argc != 1) {
  88.             if (strCmp(argv[1], "-n") == SAMESTRING)
  89.                 return ListNodes(TRUE);
  90.             if (strCmp(argv[1], "-nd") == SAMESTRING)
  91.                 return ListNodes(FALSE);
  92.             if (strCmp(argv[1], "-s") == SAMESTRING)
  93.                 return ListByNodes();
  94.         }
  95.  
  96.         printf("%s\n", cfg.codeBuf + cfg.nodeName);
  97.         for (Index = AIDEROOM + 1;              /* First 3 never shared */
  98.             Index < MAXROOMS; Index++) {
  99.             if (  roomTab[Index].rtflags.INUSE &&
  100.                         roomTab[Index].rtflags.SHARED) {
  101.                 printf("%s\n", roomTab[Index].rtname);
  102.                 for (NetRover = 0; NetRover < cfg.netSize; NetRover++) {
  103.                     CheckNet(NetRover, Index);
  104.                 }
  105.                 printf("\n");
  106.             }
  107.         }
  108.         VirtInit();
  109.         if (VirtualInUse) {
  110.             for (Index = 0; Index < VirtSize; Index++) {
  111.                 if (strLen(VRoomTab[Index].vrName) != 0) {
  112.                     printf("%s (Virtual)\n", VRoomTab[Index].vrName);
  113.                     for (NetRover = 0; NetRover < cfg.netSize; NetRover++) {
  114.                         CheckVirt(Index, NetRover);
  115.                     }
  116.                     printf("\n");
  117.                 }
  118.             }
  119.         }
  120.     }
  121. }
  122.  
  123. /*
  124.  * CheckVirt()
  125.  *
  126.  * This processes a virtual room.
  127.  */
  128. void CheckVirt(int TheVirt, int NetRover)
  129. {
  130.     int i;
  131.  
  132.     for (i = 0; i < VIRT_LIMIT; i++) {
  133.         if (VirtNetList[NetRover].VirtList[i].WhichVirt == TheVirt) {
  134.             getNet(NetRover, &netBuf);
  135.             if (netBuf.nbflags.in_use) {
  136.                 printf("        %s", netBuf.netName);
  137.                 switch (GetMode(VirtNetList[NetRover].VirtList[i].mode)) {
  138.                     case PEON: printf(" (Peon)\n"); break;
  139.                     case ACTIVE_BACKBONE:
  140.                         printf(" (Backbone - Active)\n"); break;
  141.                     case PASS_BACKBONE:
  142.                         printf(" (Backbone - Passive)\n"); break;
  143.                 }
  144.             }
  145.         }
  146.     }
  147. }
  148.  
  149. /*
  150.  * CheckNet()
  151.  *
  152.  * This checks to see if the given room is shared with this node and does
  153.  * the requisite print.
  154.  */
  155. void CheckNet(i, roomSlot)
  156. int i, roomSlot;
  157. {
  158.     int j;
  159.  
  160.     if (netTab[i].ntflags.in_use) {
  161.         for (j = 0; j < SHARED_ROOMS; j++) {
  162.             if (isSharedRoom(i, j)) {
  163.                 if (netTabRoomSlot(i, j) == roomSlot &&
  164.                         roomTab[roomSlot].rtgen == netGen(i, j)) {
  165.                     getNet(i, &netBuf);
  166.                     printf("        %s", netBuf.netName);
  167.                     if (roomTab[netRoomSlot(j)].rtShareType == PEON)
  168.                         printf(" (Peon)\n");
  169.                     else switch (GetMode(netTab[i].netTRooms[j].mode)) {
  170.                     case PEON:
  171.                         printf(" (Peon)\n");    break;
  172.                     case ACTIVE_BACKBONE:
  173.                         printf(" (Active Backbone)\n"); break;
  174.                     case PASS_BACKBONE:
  175.                         printf(" (Passive Backbone)\n");        break;
  176.                     }
  177.                     return;
  178.                 }
  179.             }
  180.         }
  181.     }
  182. }
  183.  
  184. /*
  185.  * ListNodes()
  186.  *
  187.  * This just prints the list of nodes.  If alive is set, then only print those
  188.  * nodes not disabled.
  189.  */
  190. int ListNodes(alive)
  191. int alive;
  192. {
  193.     int i;
  194.     static char *bauds[] = {
  195.     "300", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "57600"
  196.     };
  197.  
  198.     for (i = 0; i < cfg.netSize; i++) {
  199.         getNet(i, &netBuf);
  200.         if (netBuf.nbflags.in_use &&
  201.                 (!alive || (netBuf.MemberNets & ALL_NETS))) {
  202.             printf("%3d. %-21s%-21s%-11s%s\n", i, netBuf.netName, netBuf.netId,
  203.                 (netBuf.nbflags.local) ? "local" : "non-local",
  204.                 bauds[netBuf.baudCode]);
  205.         }
  206.     }
  207. }
  208.  
  209. /*
  210.  * ListByNodes()
  211.  *
  212.  * This prints out nodes and the rooms shared.
  213.  */
  214. int ListByNodes()
  215. {
  216.     int i;
  217.  
  218.     VirtInit();
  219.     for (i = 0; i < cfg.netSize; i++) {
  220.         getNet(i, &netBuf);
  221.         if (netBuf.nbflags.in_use) {
  222.             if (CheckForShared()) {
  223.                 printf("%s\n", netBuf.netName);
  224.                 PrintNetRooms();
  225.                 PrintVirtuals();
  226.                 printf("\n");
  227.             }
  228.         }
  229.     }
  230.  
  231.     return 0;
  232. }
  233.  
  234. /*
  235.  * CheckForShared()
  236.  *
  237.  * This decides if this node has any shared rooms at all.
  238.  */
  239. int CheckForShared()
  240. {
  241.     int rover, x;
  242.  
  243.     for (rover = 0; rover < SHARED_ROOMS; rover++)
  244.         if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  245.             return TRUE;
  246.  
  247.     if (!VirtualInUse) return FALSE;
  248.  
  249.     for (rover = 0; rover < VIRT_LIMIT; rover++) {
  250.         x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  251.         if (x != -1 && (x >= VirtSize || x < 0 || !VRoomInuse(x)))
  252.             VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  253.  
  254.         if ((x = VirtNetList[thisNet].VirtList[rover].WhichVirt) != -1)
  255.             return TRUE;
  256.     }
  257.     return FALSE;
  258. }
  259.  
  260. /*
  261.  * PrintNetRooms()
  262.  *
  263.  * This prints out all the net rooms for the current node.
  264.  */
  265. void PrintNetRooms()
  266. {
  267.     int rover;
  268.  
  269.     for (rover = 0; rover < SHARED_ROOMS; rover++)
  270.         if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  271.             printf("     %s\n", roomTab[netTabRoomSlot(thisNet, rover)].rtname);
  272. }
  273.  
  274. /*
  275.  * PrintVirtuals()
  276.  *
  277.  * This prints out all the virtual rooms for the current node.
  278.  */
  279. void PrintVirtuals()
  280. {
  281.     int rover, x;
  282.  
  283.     if (!VirtualInUse) return ;
  284.  
  285.     for (rover = 0; rover < VIRT_LIMIT; rover++) {
  286.         x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  287.         if (x != -1 && (x >= VirtSize || x < 0 || !VRoomInuse(x)))
  288.             VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  289.  
  290.         if ((x = VirtNetList[thisNet].VirtList[rover].WhichVirt) != -1)
  291.             printf("     %s\n", VRoomTab[x].vrName);
  292.     }
  293. }
  294.  
  295.